/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler.xml;

import bbd.crawler.fwk.BaseFactory;
import bbd.crawler.xml.handler.fwk.BaseXMLHandler;

/**
 *
 * @author Amogh
 */
public class XMLHandlerFactory extends BaseFactory {

    private static XMLHandlerFactory instance = null;

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static BaseXMLHandler getHandlerFor ( String url )
    throws ClassNotFoundException,
            InstantiationException,
            IllegalAccessException
    {
        if ( instance == null ) {

            instance = new XMLHandlerFactory();
        }

        return instance.getHandlerInstance ( url );

    } // end function getHandlerFor

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static XMLHandlerFactory getInstance ()
    {
        if ( instance == null ) {

            instance = new XMLHandlerFactory();
        }

        return instance;

    } // end function getInstance

    //--------------------------------------------------------------------------
    //                             INSTANCE METHODS
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    /** Javadoc here */
    private XMLHandlerFactory () {

        bundleBaseName = "bbd.crawler.xml.handler-map";
        basePackage    = "handler.base.package";
        baseMapConfig  = "handler.map.config";

        loadHashMap();

    } // end default constructor

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public BaseXMLHandler getHandlerInstance ( String url )
    throws ClassNotFoundException,
            InstantiationException,
            IllegalAccessException
    {

        return (BaseXMLHandler) getInstance ( getMapKey (url) );

    } // end function getHandlerInstance

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public boolean isMappingAvailable ( String rawKey ) {

        return super.isMappingAvailable ( getMapKey (rawKey) );

    } // end function isMappingAvailable

} // end class XMLHandlerFactory
